<?php
function get_ip() {
    if(getenv('HTTP_CLIENT_IP'))
        $ip = getenv('HTTP_CLIENT_IP');
    elseif($tmp = getenv('HTTP_X_FORWARDED_FOR'))
        $ip = @array_shift(explode(' ', str_replace(',', ' ', $tmp)));
    elseif(getenv('REMOTE_ADDR'))
        $ip = getenv('REMOTE_ADDR');
    else
        $ip = @$_SERVER['REMOTE_ADDR'];
    $pattern = '/^192\.168/i';
    $ok = preg_match($pattern, $ip);
    if( $ok || trim($ip) == "" )
        @$ip = $_SERVER['HTTP_X_REAL_IP'];
    return $ip;
}